package org.rcs.icm.common.utils;

import com.feinno.redis.sentinel.RedisKey;
import com.feinno.redis.sentinel.pipeline.NewPipeline;
import org.rcs.icm.cache.Redis.Base.ServiceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

/**
 * 初始化redis
 */
public class RedisLockInit {
    private final static Logger LOGGER = LoggerFactory.getLogger(RedisLockInit.class);
    private static Jedis JEDIS;

    public static void init(){
        try {
            JEDIS = new Jedis("",3607);
            RedisLockUtil.setRedisCache(new RedisLockInit.RedisCacheMe());
        } catch (Exception e) {
            LOGGER.error(e.getMessage(),e);
            LOGGER.error("redis 分布式锁初始化失败");
        }
    }

    public static class RedisCacheMe implements RedisLockUtil.RedisCache{

        @Override
        public long setnx(String k, String v) {
            return JEDIS.setnx(k,v);
        }

        @Override
        public String getSet(String k, String v) {
            return JEDIS.getSet(k,v);
        }

        @Override
        public String get(String k) {
            return JEDIS.get(k);
        }

        @Override
        public long del(String k) {
            return JEDIS.del(k);
        }
    }
}
